package com.hanrui.android.activity.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.hanrui.android.R;
import com.hanrui.android.library.base.ActionBarBaseActivity;
import com.hanrui.android.model.InvoiceListBean;
import com.hanrui.android.net.contract.mine.AddBillContract;
import com.hanrui.android.net.presenter.mine.AddBillPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 添加发票
 */
public class AddBillActivity extends ActionBarBaseActivity<AddBillPresenter> implements AddBillContract.View {

    @BindView(R.id.name)
    EditText name;
    @BindView(R.id.duty_Num)
    EditText dutyNum;
    @BindView(R.id.company_address)
    EditText companyAddress;
    @BindView(R.id.company_phone)
    EditText companyPhone;
    @BindView(R.id.bank_name)
    EditText bankName;
    @BindView(R.id.bank_num)
    EditText bankNum;
    @BindView(R.id.submit)
    TextView submit;

    InvoiceListBean bean;


    @Override
    protected void initInjector() {mActivityComponent.inject(this);}


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addbill);

        unbinder = ButterKnife.bind(this);

        mTitleBar.setTitle("编辑发票");

        Bundle bundle = getIntent().getExtras();

        bean = (InvoiceListBean) bundle.getSerializable("bean");

        if (null != bean) {

            name.setText(bean.getCompanyName());
            dutyNum.setText(bean.getDutyNo());
            companyAddress.setText(bean.getOfficeName());
            companyPhone.setText(bean.getPhone());
            bankName.setText(bean.getBankName());
            bankNum.setText(bean.getBankAccount());

        		}

    }



    @OnClick({ R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.submit:
                if (TextUtils.isEmpty(name.getText().toString())) {
                    ToastUtils.showShort("请填写公司名称");
                }
                mPresenter.invoiceSave(this,bean.getId(),
                        name.getText().toString(),
                        dutyNum.getText().toString(),
                        companyAddress.getText().toString(),
                        companyPhone.getText().toString(),bankName.getText().toString(),bankNum.getText().toString());
                break;
        }
    }


    @Override
    public void invoiceSave(int code) {

        if (code == 1) {

            ToastUtils.showShort("提交成功");
            onBackPressed();

        		}else {

            ToastUtils.showShort("提交失败");
        }

    }


    public static void start(Context context, InvoiceListBean bean){

        Intent intent = new Intent(context,AddBillActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("bean",bean);
        intent.putExtras(bundle);
        context.startActivity(intent);

    }

}
